package com.intelligent.ispc.client.ex;

import javax.swing.*;

/**
 * <b>Programm:</b> WaveGradient<br>
 * <b>Copyright:</b> 2002 Andreas Gohr, Frank Schubert<br>
 * <b>License:</b> GPL2 or higher<br>
 * <br>
 * <b>Info:</b> This JSlider uses doubles for its values
 */
public class DoubleJSlider extends JSlider {

    private int digit;


    /**
     * Constructor - initializes with 0.0,100.0,50.0
     */
    public DoubleJSlider() {
        super();
        setDoubleMinimum(0.0);
        setDoubleMaximum(100.0);
        setDoubleValue(50.0);
    }

    /**
     * Constructor.
     *
     * @param min   min value.
     * @param max   max value.
     * @param val   current value.
     * @param digit digit space.
     */
    public DoubleJSlider(double min, double max, double val, int digit) {
        super();
        setDoubleMinimum(min);
        setDoubleMaximum(max);
        setDoubleValue(val);
        setDigit(digit);
    }

    /**
     * Returns Maximum in double precision
     *
     * @return double of max
     */
    public double getDoubleMaximum() {
        return (getMaximum() / Math.pow(10, getDigit()));
    }

    /**
     * Returns Minimum in double precision
     *
     * @return double of min
     */
    public double getDoubleMinimum() {
        return (getMinimum() / Math.pow(10, getDigit()));
    }

    /**
     * Returns Value in double precision
     *
     * @return double of current value
     */
    public double getDoubleValue() {
        return (getValue());
    }

    /**
     * Sets Maximum in double precision
     *
     * @param max max value.
     */
    public void setDoubleMaximum(double max) {
        setMaximum((int) (max * Math.pow(10, getDigit())));
    }

    /**
     * sets Minimum in double precision
     *
     * @param min min value.
     */
    public void setDoubleMinimum(double min) {
        setMinimum((int) (min * Math.pow(10, getDigit())));
    }

    /**
     * sets Value in double precision
     *
     * @param val value.
     */
    public void setDoubleValue(double val) {
        setValue((int) (val));
    }

    public int getDigit() {
        return digit;
    }

    public void setDigit(int digit) {
        this.digit = digit;
    }
}
